/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-06-05 14:27:15
 * @LastEditors: kl2018
 * @LastEditTime: 2020-06-23 10:08:49
 */
import { WeaForm, WeaTableNew } from 'comsMobx';
import { observable, action, runInAction } from 'mobx';
import { Base } from '../base';
import { WeaLocaleProvider } from 'ecCom';
import * as API from '../../apis/adjustLog/AdjustLogApi';
import objectAssign from 'object-assign';

const { TableStore } = WeaTableNew;
const getLabel = WeaLocaleProvider.getLabel;

export default class AdjustLogStore extends Base {
	@observable loading = false;
	@observable tableStore// 表格数据

	form = new WeaForm();// 高级搜索
	@observable conditions = [];
	submitparams = {};

	initLoad = (params) => {
		// this.submitparams = {...params, ...{requestid:11791788, nodeid:42530, workflowid:51022}};
		this.submitparams = { ...params };
		this.loadData();
		this.loadForm();
	}

	loadForm = () => {
		// 加载高级搜索相关
		API.loadConfig(this.submitparams).then((res) => {
			const { conditions, api_status, api_message } = res;
			if (api_status) {
				runInAction(() => {
					this.form.initFormFields(conditions);
					this.conditions = conditions;
				});
			} else {
				this.showErrorMsg(api_message || getLabel(388768, '加载失败!'), 3);
			}
		});
	}

	@action
	loadData = () => {
		this.loading = true;
		const { form, submitparams } = this;
		let params = objectAssign({}, (form && form.getFormParams()) || {}, submitparams);

		API.loadDatas(params).then((res) => {
			const { sessionkey, api_status, api_message } = res;
			this.loading = false;
			if (api_status && sessionkey) {
				runInAction(() => {
					this.tableStore = (new TableStore()).getDatas(sessionkey);
				});
			} else {
				this.showErrorMsg(api_message || getLabel(388768, '加载失败!'), 3);
			}
		});
	}

	destory = () => {
		this.form.reset();
		this.tableStore = null;
	}
}
